"""
    Created By Khun on 2020/4/7
"""

__author__ = 'Khun'

from sqlalchemy import Column, Integer, String, ForeignKey, Text
from sqlalchemy.orm import relationship

from app.models.base import Base


class Types(Base):
    """ 模板分类 """

    tid = Column(Integer, primary_key=True, autoincrement=True)
    type_name = Column(String(100))
    type_tem = relationship('Throw', backref='types', lazy='dynamic')

    def __str__(self):
        return self.type_name


class Throw(Base):
    """ 模板管理 """

    tid = Column(Integer, primary_key=True, autoincrement=True)
    temp_name = Column(String(100), nullable=False)
    temp_path = Column(String(100), nullable=False)
    path_url = Column(String(100))
    types_id = Column(Integer, ForeignKey('types.tid'))
    manage_tem = relationship('Manage', backref='manage', lazy='dynamic')

    def __str__(self):
        return self.temp_name


class Manage(Base):
    """ 投放管理 """

    tid = Column(Integer, primary_key=True, autoincrement=True)
    web_url = Column(String(100), nullable=False)
    wechat = Column(String(100), nullable=False)
    throw_tid = Column(Integer, ForeignKey('throw.tid'))
    cnzz = Column(Integer)
    copyright_ = Column(String(100))
    base_js = Column(Text)
    transfer = Column(String(255))
    third_api = Column(Text)
    remark = Column(Text)

    def __str__(self):
        return self.web_url
